import java.util.LinkedList;
import java.util.Queue;

public class MoveZero {
    public void moveZeroes(int[] nums) {
        int count = 0;
        Queue<Integer> queue = new LinkedList<Integer>();
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                count++;
            } else {
                queue.offer(nums[i]);
            }
        }

        for (int i = 0; i < nums.length; i++) {
            if (i < nums.length - count) {
                nums[i] = queue.poll();
            } else {
                nums[i] = 0;
            }
        }
    }
    public void moveZeroes2(int[] nums) {
        int left = -1;
        int right = 0;
        while (right < nums.length) {
            if (nums[right] != 0) {
                left++;
                swap(nums, left, right);
            }
            right++;
        }
    }

    public void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
